home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 17595 < prev    next >
Encoding:
Text File  |  1996-08-05  |  949 b   |  48 lines

  1. Path: in1.uu.net!demos!usenet
  2. From: Alexey Ruzin <00alex@demos.su>
  3. Newsgroups: comp.lang.c++
  4. Subject: BC 3.1 - 4.5 (error!?)
  5. Date: Tue, 16 Apr 1996 21:17:28 +0400
  6. Organization: Demos Online Service
  7. Message-ID: <3173D628.48F6@demos.su>
  8. NNTP-Posting-Host: 00alex@dbs.demos.su
  9. Mime-Version: 1.0
  10. Content-Type: text/plain; charset=us-ascii
  11. Content-Transfer-Encoding: 7bit
  12. X-Mailer: Mozilla 2.0 (X11; I; SunOS 5.4 sun4m)
  13.  
  14. Hi, All
  15.  
  16. Here is simple example of abnormal programming.
  17. But BC crashed (sorry, it works and even compiles
  18. the program, but it is unpredictable what will occur)
  19. on it:
  20.  
  21. #include <stdio.h>
  22.  
  23. int st_func( int a )
  24. {
  25.   static int p=a;
  26.   return p++;
  27. }
  28.  
  29. int main( int argc, char *argv[] )
  30. {
  31.   int i;
  32.   if( argc != 1 )
  33.   {
  34.     for( i = 10; i>0; i-- )
  35.       printf( "%d\n", st_func( i ) );
  36.   }
  37.   else
  38.   {
  39.     for( i = 0; i<10; i++ )
  40.       printf( "%d\n", st_func( i ) );
  41.   }
  42.   return 0;
  43. }
  44.  
  45. Enjoy...
  46.  
  47. If you know what is wrong reply please :)
  48.